package com. hafu. view. GYS;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com. hafu. model. GysInfo;
import com. hafu. service. GysInfoService;
import com. hafu. util. StringUtil;
import java. awt.*;
import java. awt. event.*;
import javax. swing.*;
import javax. swing. GroupLayout;
public class AddGYSFrm extends JFrame {
    private GysInfoService gysInfoService = new GysInfoService();

    public AddGYSFrm() {
        initComponents();
    }

    private void button1(ActionEvent e) {
        String name = textField1.getText();
        String tel = textField2.getText();
        if (StringUtil.isEmpty(name)) {
            JOptionPane.showMessageDialog(null, "供应商名称不能为空");
            return;
        }
        if (StringUtil.isEmpty(tel)) {
            JOptionPane.showMessageDialog(null, "供应商电话不能为空");
            return;
        }
        GysInfo gysInfo = new GysInfo(name, tel);
        Boolean aBoolean = gysInfoService.addGysInfo(gysInfo);
        if (aBoolean) {
            JOptionPane.showMessageDialog(null, "添加成功");
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(null, "添加失败");
        }
    }

    private void initComponents() {
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        textField2 = new JTextField();
        button1 = new JButton();
        setTitle("\u6dfb\u52a0\u4f9b\u5e94\u5546");
        Container contentPane = getContentPane();
        label1.setText("\u4f9b\u5e94\u5546\u540d\u5b57");
        label2.setText("\u4f9b\u5e94\u5546\u7535\u8bdd");
        button1.setText("\u63d0\u4ea4");
        button1.addActionListener(e -> button1(e));
        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGroup(contentPaneLayout.createParallelGroup()
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(107, 107, 107)
                                                .addGroup(contentPaneLayout.createParallelGroup()
                                                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(label2, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE))
                                                .addGap(58, 58, 58)
                                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                                                        .addComponent(textField1, GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)))
                                        .addGroup(contentPaneLayout.createSequentialGroup()
                                                .addGap(203, 203, 203)
                                                .addComponent(button1, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)))
                                .addContainerGap(235, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
                contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                                .addGap(76, 76, 76)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label1)
                                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(38, 38, 38)
                                .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label2)
                                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                                GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 121, Short.MAX_VALUE)
                                .addComponent(button1)
                                .addGap(104, 104, 104))
        );
        pack();
        setLocationRelativeTo(getOwner());
    }

    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JTextField textField2;
    private JButton button1;

    private void button_handle(ActionEvent e) {
        // TODO add your code here
    }


    

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - wmy
    private JButton button1;
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JTextField textField2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:o

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - wmy
        button1 = new JButton();
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();

        //======== this ========
        setTitle("\u6dfb\u52a0\u4f9b\u5e94\u5546");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("\u63d0\u4ea4");
        button1.setBorder(new MatteBorder(1, 1, 1, 1, Color.black));
        button1.addActionListener(e -> button_handle(e));
        contentPane.add(button1);
        button1.setBounds(180, 240, 113, button1.getPreferredSize().height);

        //---- label1 ----
        label1.setText("\u4f9b\u5e94\u5546\u540d\u5b57");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(100, 110), label1.getPreferredSize()));

        //---- label2 ----
        label2.setText("\u4f9b\u5e94\u5546\u7535\u8bdd");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(100, 170), label2.getPreferredSize()));
        contentPane.add(textField1);
        textField1.setBounds(190, 100, 135, 35);
        contentPane.add(textField2);
        textField2.setBounds(190, 160, 135, 35);

        contentPane.setPreferredSize(new Dimension(495, 385));
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }
}
